import service from "@/axios";

export function login(username, password) {
  const data = `username=${username}&password=${password}`;
  return service({
    method: "POST",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    data: data,
    url: "/login",
  });
}

export function getUser() {
  return service("/user");
}

export function modifyPassword(id, form) {
  return service({
    method: "PUT",
    url: "/user/modify_password/" + id,
    data: form,
  });
}

export function save_project(project_form, project_menbers_forms) {
  return service({
    method: "POST",
    url: "/save_project/",
    data: {
      project_form: project_form,
      project_menbers_forms: project_menbers_forms,
    },
  });
}

export function submit_project(project_form, project_menbers_forms) {
  return service({
    method: "POST",
    url: "/submit_project",
    data: {
      project_form: project_form,
      project_menbers_forms: project_menbers_forms,
    },
  });
}

export function save_files(id, data) {
  return service({
    method: "POST",
    url: "/save_files?project_id=" + id,
    data: data,
  });
}

export function cancelProject(id) {
  return service({
    method: "POST",
    url: "/cancelProject?id=" + id,
    data: "",
  });
}

export function getStatistics() {
  return service.get("/getStatistics");
}

export function getDepartments() {
  return service.get("/getDepartments");
}

export function getProjectGroups() {
  return service.get("/getProjectGroups");
}

export function getProjectClass() {
  return service.get("/getProjectClass");
}

export function getProjectType() {
  return service.get("/getProjectType");
}

export function getProjectGroupMemberRole() {
  return service.get("/getProjectGroupMemberRole");
}

export function getProjectsByUser(limit, page, queryForm) {
  return service({
    method: "POST",
    url: "/getProjectsByUser",
    params: {
      limit: limit,
      page: page,
    },
    data: queryForm,
  });
}

export function download_file(id) {
  return service({
    method: "GET",
    url: "/download_file/" + id,
  });
}

export function getUserGroups() {
  return service({
    method: "GET",
    url: "/getUserGroups",
  });
}

export function getTaggingProjects(limit, page, project_group) {
  return service({
    method: "POST",
    url: "/getTaggingProjects",
    params: {
      limit: limit,
      page: page,
      project_group: project_group,
    },
  });
}

export function tag_batch(batch_name, group_name, ids) {
  return service({
    method: "POST",
    url: "/tag_batch",
    params: {
      'batch_name': batch_name,
      'group_name': group_name,
    },
    data: ids,
  });
}

export function getBatches(group_name) {
  return service({
    method: "POST",
    url: "/getBatches",
    params: {
      group_name: group_name,
    },
  });
}

export function createBatch(group_name, batch_name) {
  return service({
    method: "POST",
    url: "/createBatch",
    data: {
      group_name: group_name,
      batch_name: batch_name,
    },
  });
}

export function deleteBatch(id){
  return service({
    method: "POST",
    url: "/deleteBatch",
    params: {
      'id': id
    },
  });
}

export function getProjectsByGroup(batch_name,limit,page){
  return service({
    method: "POST",
    url: "/getProjectsByGroup",
    params: {
      'batch_name': batch_name,
      'limit':limit,
      'page':page
    },
  });
}

export function getProjectsByBoard(batch_name,limit,page){
  return service({
    method: "POST",
    url: "/getProjectsByGroup",
    params: {
      'batch_name': batch_name,
      'limit':limit,
      'page':page
    },
    data: ['专家组会审通过','创新委员会会审']
  });
}

export function getAuditedProject(batch_name,limit,page){
  return service({
    method: "GET",
    url: "/getAuditedProject",
    params: {
      'batch_name': batch_name,
      'limit':limit,
      'page':page
    }
  });
}

export function getAuditRule(group_name){
  return service({
    method: "GET",
    url: "/auditRule",
    params: {
      'group_name': group_name
    }
  });
}

export function audit(project_id,pointsForm){
  return service({
    method: "POST",
    url: "/audit",
    params: {
      'project_id': project_id
    },
    data: pointsForm
  });
}

export function getBatchProjectsWithAuditInfo(group_name,batch_name,isFile=false,limit,page){
  if (isFile){
    return service({
      method: "GET",
      url: "/getBatchProjectsWithAuditInfo",
      params: {
        "group_name": group_name,
        "batch_name":batch_name,
        "isFile":isFile,
        "limit":limit,
        "page":page,
      },
      responseType: "blob"
    });
  }
  else{
    return service({
      method: "GET",
      url: "/getBatchProjectsWithAuditInfo",
      params: {
        "group_name": group_name,
        "batch_name":batch_name,
        "isFile":isFile,
        "limit":limit,
        "page":page,
      }
    });
  }
  
}

export function getProjectByProjectCode(project_code){
  return service({
    method: "GET",
    url: "/getProjectByProjectCode",
    params: {
      'project_code': project_code
    }
  });
}

export function submitProjectAuditRes(project_id,project_group,isPassed,project_type=null){
  return service({
    method: "POST",
    url: "/submitProjectAuditRes",
    params: {
      'project_id': project_id,
      'project_group': project_group,
      'isPassed': isPassed,
      'project_type': project_type,
    }
  });
}